<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>第二章实训</title>
<!-- 2019-09-09 一 23:42 -->
<meta  http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta  name="generator" content="Org-mode" />
<meta  name="author" content="jacklisp" />
<style type="text/css">
 <!--/*--><![CDATA[/*><!--*/
  .title  { text-align: center; }
  .todo   { font-family: monospace; color: red; }
  .done   { color: green; }
  .tag    { background-color: #eee; font-family: monospace;
            padding: 2px; font-size: 80%; font-weight: normal; }
  .timestamp { color: #bebebe; }
  .timestamp-kwd { color: #5f9ea0; }
  .right  { margin-left: auto; margin-right: 0px;  text-align: right; }
  .left   { margin-left: 0px;  margin-right: auto; text-align: left; }
  .center { margin-left: auto; margin-right: auto; text-align: center; }
  .underline { text-decoration: underline; }
  #postamble p, #preamble p { font-size: 90%; margin: .2em; }
  p.verse { margin-left: 3%; }
  pre {
    border: 1px solid #ccc;
    box-shadow: 3px 3px 3px #eee;
    padding: 8pt;
    font-family: monospace;
    overflow: auto;
    margin: 1.2em;
  }
  pre.src {
    position: relative;
    overflow: visible;
    padding-top: 1.2em;
  }
  pre.src:before {
    display: none;
    position: absolute;
    background-color: white;
    top: -10px;
    right: 10px;
    padding: 3px;
    border: 1px solid black;
  }
  pre.src:hover:before { display: inline;}
  pre.src-sh:before    { content: 'sh'; }
  pre.src-bash:before  { content: 'sh'; }
  pre.src-emacs-lisp:before { content: 'Emacs Lisp'; }
  pre.src-R:before     { content: 'R'; }
  pre.src-perl:before  { content: 'Perl'; }
  pre.src-java:before  { content: 'Java'; }
  pre.src-sql:before   { content: 'SQL'; }

  table { border-collapse:collapse; }
  caption.t-above { caption-side: top; }
  caption.t-bottom { caption-side: bottom; }
  td, th { vertical-align:top;  }
  th.right  { text-align: center;  }
  th.left   { text-align: center;   }
  th.center { text-align: center; }
  td.right  { text-align: right;  }
  td.left   { text-align: left;   }
  td.center { text-align: center; }
  dt { font-weight: bold; }
  .footpara:nth-child(2) { display: inline; }
  .footpara { display: block; }
  .footdef  { margin-bottom: 1em; }
  .figure { padding: 1em; }
  .figure p { text-align: center; }
  .inlinetask {
    padding: 10px;
    border: 2px solid gray;
    margin: 10px;
    background: #ffffcc;
  }
  #org-div-home-and-up
   { text-align: right; font-size: 70%; white-space: nowrap; }
  textarea { overflow-x: auto; }
  .linenr { font-size: smaller }
  .code-highlighted { background-color: #ffff00; }
  .org-info-js_info-navigation { border-style: none; }
  #org-info-js_console-label
    { font-size: 10px; font-weight: bold; white-space: nowrap; }
  .org-info-js_search-highlight
    { background-color: #ffff00; color: #000000; font-weight: bold; }
  /*]]>*/-->
</style>
<link rel="stylesheet" type="text/css" href="css/markdownpad-github.css" />
<script type="text/javascript">
/*
@licstart  The following is the entire license notice for the
JavaScript code in this tag.

Copyright (C) 2012-2013 Free Software Foundation, Inc.

The JavaScript code in this tag is free software: you can
redistribute it and/or modify it under the terms of the GNU
General Public License (GNU GPL) as published by the Free Software
Foundation, either version 3 of the License, or (at your option)
any later version.  The code is distributed WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE.  See the GNU GPL for more details.

As additional permission under GNU GPL version 3 section 7, you
may distribute non-source (e.g., minimized or compacted) forms of
that code without the copy of the GNU GPL normally required by
section 4, provided you include this license notice and a URL
through which recipients can access the Corresponding Source.


@licend  The above is the entire license notice
for the JavaScript code in this tag.
*/
<!--/*--><![CDATA[/*><!--*/
 function CodeHighlightOn(elem, id)
 {
   var target = document.getElementById(id);
   if(null != target) {
     elem.cacheClassElem = elem.className;
     elem.cacheClassTarget = target.className;
     target.className = "code-highlighted";
     elem.className   = "code-highlighted";
   }
 }
 function CodeHighlightOff(elem, id)
 {
   var target = document.getElementById(id);
   if(elem.cacheClassElem)
     elem.className = elem.cacheClassElem;
   if(elem.cacheClassTarget)
     target.className = elem.cacheClassTarget;
 }
/*]]>*///-->
</script>
</head>
<body>
<div id="content">
<h1 class="title">第二章实训</h1>
<div id="table-of-contents">
<h2>Table of Contents</h2>
<div id="text-table-of-contents">
<ul>
<li><a href="#sec-1">1. 字符串、颜色等资源应用实训</a>
<ul>
<li><a href="#sec-1-1">1.1. 在Android Studio中新建空白项目，并将其命名为ValuesResDemo。</a></li>
<li><a href="#sec-1-2">1.2. 在res目录下完成颜色资源文件colors.xml、字符串资源文件strings.xml以及尺寸资源文件dimens.xml的定义。</a></li>
<li><a href="#sec-1-3">1.3. 添加控件，完成layout目录下布局文件。</a></li>
<li><a href="#sec-1-4">1.4. 对Java文件进行功能增加，完成代码。</a></li>
<li><a href="#sec-1-5">1.5. 颜色资源文件color.xml关键代码如下图所示</a></li>
<li><a href="#sec-1-6">1.6. 字符串资源文件stings.xml的关键代码如下:</a></li>
<li><a href="#sec-1-7">1.7. 尺寸资源关键代码如下:</a></li>
<li><a href="#sec-1-8">1.8. 布局文件activity_main.xml关键代码如下:</a></li>
<li><a href="#sec-1-9">1.9. java关键代码如下:</a></li>
</ul>
</li>
<li><a href="#sec-2">2. Android应用国际化实训</a>
<ul>
<li><a href="#sec-2-1">2.1. 项目实现过程:</a></li>
<li><a href="#sec-2-2">2.2. 关键代码</a></li>
</ul>
</li>
</ul>
</div>
</div>

<div id="outline-container-sec-1" class="outline-2">
<h2 id="sec-1"><span class="section-number-2">1</span> 字符串、颜色等资源应用实训</h2>
<div class="outline-text-2" id="text-1">
</div><div id="outline-container-sec-1-1" class="outline-3">
<h3 id="sec-1-1"><span class="section-number-3">1.1</span> 在Android Studio中新建空白项目，并将其命名为ValuesResDemo。</h3>
</div>
<div id="outline-container-sec-1-2" class="outline-3">
<h3 id="sec-1-2"><span class="section-number-3">1.2</span> 在res目录下完成颜色资源文件colors.xml、字符串资源文件strings.xml以及尺寸资源文件dimens.xml的定义。</h3>
</div>
<div id="outline-container-sec-1-3" class="outline-3">
<h3 id="sec-1-3"><span class="section-number-3">1.3</span> 添加控件，完成layout目录下布局文件。</h3>
</div>
<div id="outline-container-sec-1-4" class="outline-3">
<h3 id="sec-1-4"><span class="section-number-3">1.4</span> 对Java文件进行功能增加，完成代码。</h3>
</div>
<div id="outline-container-sec-1-5" class="outline-3">
<h3 id="sec-1-5"><span class="section-number-3">1.5</span> 颜色资源文件color.xml关键代码如下图所示</h3>
<div class="outline-text-3" id="text-1-5">

<div class="figure">
<p><img src="img/1.jpg" alt="1.jpg" />
</p>
</div>
</div>
</div>
<div id="outline-container-sec-1-6" class="outline-3">
<h3 id="sec-1-6"><span class="section-number-3">1.6</span> 字符串资源文件stings.xml的关键代码如下:</h3>
<div class="outline-text-3" id="text-1-6">
<div class="org-src-container">

<pre class="src src-xml">&lt;?<span style="color: #80A0C2;">xml</span> <span style="color: #7d7d7d;">version="1.0" encodng="utf-8"</span>?&gt;
&lt;<span style="color: #8EBCBB;">resources</span>&gt;
  &lt;<span style="color: #8EBCBB;">string</span> <span style="color: #dac6d6;">name</span>=<span style="color: #A2BF8A;">"</span><span style="color: #A2BF8A;">app_name</span><span style="color: #A2BF8A;">"</span>&gt;&#23383;&#31526;&#20018;&#12289;&#39068;&#33394;&#12289;&#23610;&#23544;&#36164;&#28304;&lt;/<span style="color: #8EBCBB;">string</span>&gt;
  &lt;<span style="color: #8EBCBB;">string</span> <span style="color: #dac6d6;">name</span>=<span style="color: #A2BF8A;">"</span><span style="color: #A2BF8A;">c3</span><span style="color: #A2BF8A;">"</span>&gt;00F&lt;/<span style="color: #8EBCBB;">string</span>&gt;
  &lt;<span style="color: #8EBCBB;">string</span> <span style="color: #dac6d6;">name</span>=<span style="color: #A2BF8A;">"</span><span style="color: #A2BF8A;">c4</span><span style="color: #A2BF8A;">"</span>&gt;0FF&lt;/<span style="color: #8EBCBB;">string</span>&gt;
  &lt;<span style="color: #8EBCBB;">string</span> <span style="color: #dac6d6;">name</span>=<span style="color: #A2BF8A;">"</span><span style="color: #A2BF8A;">c5</span><span style="color: #A2BF8A;">"</span>&gt;F0F&lt;/<span style="color: #8EBCBB;">string</span>&gt;
  &lt;<span style="color: #8EBCBB;">string</span> <span style="color: #dac6d6;">name</span>=<span style="color: #A2BF8A;">"</span><span style="color: #A2BF8A;">c6</span><span style="color: #A2BF8A;">"</span>&gt;FF0&lt;/<span style="color: #8EBCBB;">string</span>&gt;
  &lt;<span style="color: #8EBCBB;">string</span> <span style="color: #dac6d6;">name</span>=<span style="color: #A2BF8A;">"</span><span style="color: #A2BF8A;">c7</span><span style="color: #A2BF8A;">"</span>&gt;07F&lt;/<span style="color: #8EBCBB;">string</span>&gt;
  &lt;<span style="color: #8EBCBB;">string</span> <span style="color: #dac6d6;">name</span>=<span style="color: #A2BF8A;">"</span><span style="color: #A2BF8A;">c8</span><span style="color: #A2BF8A;">"</span>&gt;70F&lt;/<span style="color: #8EBCBB;">string</span>&gt;
  &lt;<span style="color: #8EBCBB;">string</span> <span style="color: #dac6d6;">name</span>=<span style="color: #A2BF8A;">"</span><span style="color: #A2BF8A;">c9</span><span style="color: #A2BF8A;">"</span>&gt;F70&lt;/<span style="color: #8EBCBB;">string</span>&gt;
&lt;/<span style="color: #8EBCBB;">resources</span>&gt;
</pre>
</div>
</div>
</div>
<div id="outline-container-sec-1-7" class="outline-3">
<h3 id="sec-1-7"><span class="section-number-3">1.7</span> 尺寸资源关键代码如下:</h3>
<div class="outline-text-3" id="text-1-7">
<div class="org-src-container">

<pre class="src src-xml">   &lt;?<span style="color: #80A0C2;">xml</span> <span style="color: #7d7d7d;">version="1.0" encoding="utf-8"</span>?&gt;
&lt;<span style="color: #8EBCBB;">resources</span>&gt;
    &lt;<span style="color: #8EBCBB;">dimen</span> <span style="color: #dac6d6;">name</span>=<span style="color: #A2BF8A;">"</span><span style="color: #A2BF8A;">spacing</span><span style="color: #A2BF8A;">"</span>&gt;8dp&lt;/<span style="color: #8EBCBB;">dimen</span>&gt;
    <span style="color: #75715E;">&lt;!--</span><span style="color: #747474;"> &#23450;&#20041;GridView&#32452;&#20214;&#20013;&#27599;&#20010;&#21333;&#20803;&#26684;&#30340;&#23485;&#24230;&#12289;&#39640;&#24230; </span><span style="color: #75715E;">--&gt;</span>
    &lt;<span style="color: #8EBCBB;">dimen</span> <span style="color: #dac6d6;">name</span>=<span style="color: #A2BF8A;">"</span><span style="color: #A2BF8A;">cell_width</span><span style="color: #A2BF8A;">"</span>&gt;60dp&lt;/<span style="color: #8EBCBB;">dimen</span>&gt;
    &lt;<span style="color: #8EBCBB;">dimen</span> <span style="color: #dac6d6;">name</span>=<span style="color: #A2BF8A;">"</span><span style="color: #A2BF8A;">cell_height</span><span style="color: #A2BF8A;">"</span>&gt;66dp&lt;/<span style="color: #8EBCBB;">dimen</span>&gt;
    <span style="color: #75715E;">&lt;!--</span><span style="color: #747474;"> &#23450;&#20041;&#20027;&#31243;&#24207;&#30340;&#26631;&#39064;&#30340;&#23383;&#20307;&#22823;&#23567; </span><span style="color: #75715E;">--&gt;</span>
    &lt;<span style="color: #8EBCBB;">dimen</span> <span style="color: #dac6d6;">name</span>=<span style="color: #A2BF8A;">"</span><span style="color: #A2BF8A;">title_font_size</span><span style="color: #A2BF8A;">"</span>&gt;18sp&lt;/<span style="color: #8EBCBB;">dimen</span>&gt;
&lt;/<span style="color: #8EBCBB;">resources</span>&gt;
</pre>
</div>
</div>
</div>

<div id="outline-container-sec-1-8" class="outline-3">
<h3 id="sec-1-8"><span class="section-number-3">1.8</span> 布局文件activity_main.xml关键代码如下:</h3>
<div class="outline-text-3" id="text-1-8">
<div class="org-src-container">

<pre class="src src-xml">&lt;<span style="color: #8EBCBB;">TextView</span>
     <span style="color: #8EBCBB;">android</span>:<span style="color: #dac6d6;">layout_width</span>=<span style="color: #A2BF8A;">"</span><span style="color: #A2BF8A;">wrap_content</span><span style="color: #A2BF8A;">"</span>
     <span style="color: #8EBCBB;">android</span>:<span style="color: #dac6d6;">layout_height</span>=<span style="color: #A2BF8A;">"</span><span style="color: #A2BF8A;">wrap_content</span><span style="color: #A2BF8A;">"</span>
     <span style="color: #8EBCBB;">android</span>:<span style="color: #dac6d6;">text</span>=<span style="color: #A2BF8A;">"</span><span style="color: #A2BF8A;">@string/app_name</span><span style="color: #A2BF8A;">"</span>
     <span style="color: #8EBCBB;">android</span>:<span style="color: #dac6d6;">gravity</span>=<span style="color: #A2BF8A;">"</span><span style="color: #A2BF8A;">center</span><span style="color: #A2BF8A;">"</span>
     <span style="color: #8EBCBB;">android</span>:<span style="color: #dac6d6;">textSize</span>=<span style="color: #A2BF8A;">"</span><span style="color: #A2BF8A;">@dimen/title_font_size</span><span style="color: #A2BF8A;">"</span>/&gt;
     &lt;<span style="color: #8EBCBB;">GridView</span>
     <span style="color: #8EBCBB;">android</span>:<span style="color: #dac6d6;">id</span>=<span style="color: #A2BF8A;">"</span><span style="color: #A2BF8A;">@+id/grid01</span><span style="color: #A2BF8A;">"</span>
     <span style="color: #8EBCBB;">android</span>:<span style="color: #dac6d6;">layout_width</span>=<span style="color: #A2BF8A;">"</span><span style="color: #A2BF8A;">wrap_content</span><span style="color: #A2BF8A;">"</span>
     <span style="color: #8EBCBB;">android</span>:<span style="color: #dac6d6;">layout_height</span>=<span style="color: #A2BF8A;">"</span><span style="color: #A2BF8A;">wrap_content</span><span style="color: #A2BF8A;">"</span>
     <span style="color: #8EBCBB;">android</span>:<span style="color: #dac6d6;">horizontalSpacing</span>=<span style="color: #A2BF8A;">"</span><span style="color: #A2BF8A;">@dimen/spacing</span><span style="color: #A2BF8A;">"</span>
     <span style="color: #8EBCBB;">android</span>:<span style="color: #dac6d6;">verticalSpacing</span>=<span style="color: #A2BF8A;">"</span><span style="color: #A2BF8A;">@dimen/spacing</span><span style="color: #A2BF8A;">"</span>
     <span style="color: #8EBCBB;">android</span>:<span style="color: #dac6d6;">numColumns</span>=<span style="color: #A2BF8A;">"</span><span style="color: #A2BF8A;">3</span><span style="color: #A2BF8A;">"</span>
     <span style="color: #8EBCBB;">android</span>:<span style="color: #dac6d6;">gravity</span>=<span style="color: #A2BF8A;">"</span><span style="color: #A2BF8A;">center</span><span style="color: #A2BF8A;">"</span>&gt;
</pre>
</div>
</div>
</div>

<div id="outline-container-sec-1-9" class="outline-3">
<h3 id="sec-1-9"><span class="section-number-3">1.9</span> java关键代码如下:</h3>
<div class="outline-text-3" id="text-1-9">
<div class="org-src-container">

<pre class="src src-java">   <span style="color: #80A0C2;">package</span>  siso.edu.cn.<span style="color: #B58DAE;">valuesresdemo</span>;
<span style="color: #80A0C2;">import</span> <span style="color: #B58DAE;">android</span>.<span style="color: #B58DAE;">app</span>.<span style="color: #ECCC87;">Activity</span>;
<span style="color: #80A0C2;">import</span> <span style="color: #B58DAE;">android</span>.<span style="color: #B58DAE;">content</span>.<span style="color: #B58DAE;">res</span>.<span style="color: #ECCC87;">Resources</span>;
<span style="color: #80A0C2;">import</span> <span style="color: #B58DAE;">android</span>.<span style="color: #B58DAE;">os</span>.<span style="color: #ECCC87;">Bundle</span>;
<span style="color: #80A0C2;">import</span> <span style="color: #B58DAE;">android</span>.<span style="color: #B58DAE;">view</span>.<span style="color: #ECCC87;">View</span>;
<span style="color: #80A0C2;">import</span> <span style="color: #B58DAE;">android</span>.<span style="color: #B58DAE;">view</span>.<span style="color: #ECCC87;">ViewGroup</span>;
<span style="color: #80A0C2;">import</span> <span style="color: #B58DAE;">android</span>.<span style="color: #B58DAE;">widget</span>.<span style="color: #ECCC87;">BaseAdapter</span>;
<span style="color: #80A0C2;">import</span> <span style="color: #B58DAE;">android</span>.<span style="color: #B58DAE;">widget</span>.<span style="color: #ECCC87;">GridView</span>;
<span style="color: #80A0C2;">import</span> <span style="color: #B58DAE;">android</span>.<span style="color: #B58DAE;">widget</span>.<span style="color: #ECCC87;">TextView</span>;

<span style="color: #80A0C2;">public</span> <span style="color: #80A0C2;">class</span> <span style="color: #ECCC87;">MainActivity</span> <span style="color: #80A0C2;">extends</span> <span style="color: #ECCC87;">Activity</span>
{
    <span style="color: #75715E;">// </span><span style="color: #747474;">&#23450;&#20041;&#23383;&#31526;&#20018;&#36164;&#28304;&#25968;&#32452;&#65292;&#30452;&#25509;&#23450;&#20041;</span>
    <span style="color: #ECCC87;">int</span>[] <span style="color: #dac6d6;">textIds</span> = <span style="color: #80A0C2;">new</span> <span style="color: #ECCC87;">int</span>[]
        {
            R.string.c1 , R.string.c2 , R.string.c3 ,
            R.string.c4 , R.string.c5 , R.string.c6 ,
            R.string.c7 , R.string.c8 , R.string.c9
        };
    <span style="color: #75715E;">// </span><span style="color: #747474;">&#23450;&#20041;&#39068;&#33394;&#36164;&#28304;&#25968;&#32452;&#65292;&#20351;&#29992;&#20102;colors.xml&#20013;&#23450;&#20041;&#30340;&#36164;&#28304;</span>
    <span style="color: #ECCC87;">int</span>[] <span style="color: #dac6d6;">colorIds</span> = <span style="color: #80A0C2;">new</span> <span style="color: #ECCC87;">int</span>[]
        {
            R.color.c1 , R.color.c2 , R.color.c3 ,
            R.color.c4 , R.color.c5 , R.color.c6 ,
            R.color.c7 , R.color.c8 , R.color.c9
        };
    <span style="color: #B58DAE;">@Override</span>
    <span style="color: #80A0C2;">public</span> <span style="color: #ECCC87;">void</span> <span style="color: #8EBCBB;">onCreate</span>(<span style="color: #ECCC87;">Bundle</span> <span style="color: #dac6d6;">savedInstanceState</span>)
    {
        <span style="color: #80A0C2;">super</span>.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        <span style="color: #75715E;">// </span><span style="color: #747474;">&#21019;&#24314;&#19968;&#20010;BaseAdapter&#23545;&#35937;</span>
        <span style="color: #ECCC87;">BaseAdapter</span> <span style="color: #dac6d6;">ba</span> = <span style="color: #80A0C2;">new</span> <span style="color: #ECCC87;">BaseAdapter</span>()
        {
            <span style="color: #B58DAE;">@Override</span>
            <span style="color: #80A0C2;">public</span> <span style="color: #ECCC87;">int</span> <span style="color: #8EBCBB;">getCount</span>()
            {
                <span style="color: #75715E;">// </span><span style="color: #747474;">&#36820;&#22238;&#20540;&#23601;&#26159;&#23383;&#31526;&#20018;&#36164;&#28304;&#30340;&#38271;&#24230;&#65288;&#19968;&#20849;&#21253;&#21547;9&#20010;&#36873;&#39033;&#65289;</span>
                <span style="color: #80A0C2;">return</span> textIds.length;
            }
            <span style="color: #B58DAE;">@Override</span>
            <span style="color: #80A0C2;">public</span> <span style="color: #ECCC87;">Object</span> <span style="color: #8EBCBB;">getItem</span>(<span style="color: #ECCC87;">int</span> <span style="color: #dac6d6;">position</span>)
            {
                <span style="color: #75715E;">// </span><span style="color: #747474;">&#36820;&#22238;&#25351;&#23450;&#20301;&#32622;&#30340;&#23383;&#31526;&#20018;&#25991;&#26412;&#20540;</span>
                <span style="color: #80A0C2;">return</span> getResources().getText(textIds[position]);
            }
            <span style="color: #B58DAE;">@Override</span>
            <span style="color: #80A0C2;">public</span> <span style="color: #ECCC87;">long</span> <span style="color: #8EBCBB;">getItemId</span>(<span style="color: #ECCC87;">int</span> <span style="color: #dac6d6;">position</span>)
            {
                <span style="color: #80A0C2;">return</span> position;
            }
            <span style="color: #75715E;">// </span><span style="color: #747474;">&#37325;&#20889;&#35813;&#26041;&#27861;&#65292;&#35813;&#26041;&#27861;&#36820;&#22238;&#30340;View&#23558;&#20316;&#20026;GridView&#30340;&#27599;&#20010;&#26684;&#23376;</span>
            <span style="color: #B58DAE;">@Override</span>
            <span style="color: #80A0C2;">public</span> <span style="color: #ECCC87;">View</span> <span style="color: #8EBCBB;">getView</span>(<span style="color: #ECCC87;">int</span> <span style="color: #dac6d6;">position</span>
                    , <span style="color: #ECCC87;">View</span> <span style="color: #dac6d6;">convertView</span>, <span style="color: #ECCC87;">ViewGroup</span> <span style="color: #dac6d6;">parent</span>)
            {
                <span style="color: #ECCC87;">TextView</span> <span style="color: #dac6d6;">text</span> = <span style="color: #80A0C2;">new</span> <span style="color: #ECCC87;">TextView</span>(MainActivity.<span style="color: #80A0C2;">this</span>);
                <span style="color: #ECCC87;">Resources</span> <span style="color: #dac6d6;">res</span> = MainActivity.<span style="color: #80A0C2;">this</span>.getResources();
                <span style="color: #75715E;">// </span><span style="color: #747474;">&#20351;&#29992;&#23610;&#24230;&#36164;&#28304;&#26469;&#35774;&#32622;&#25991;&#26412;&#26694;&#30340;&#39640;&#24230;&#12289;&#23485;&#24230;</span>
                text.setWidth(60);
                text.setHeight((<span style="color: #ECCC87;">int</span>) res.getDimension(R.dimen.cell_height));
                <span style="color: #75715E;">// </span><span style="color: #747474;">&#20351;&#29992;&#23383;&#31526;&#20018;&#36164;&#28304;&#35774;&#32622;&#25991;&#26412;&#26694;&#30340;&#20869;&#23481;</span>
                text.setText(textIds[position]);
                <span style="color: #75715E;">// </span><span style="color: #747474;">&#20351;&#29992;&#39068;&#33394;&#36164;&#28304;&#26469;&#35774;&#32622;&#25991;&#26412;&#26694;&#30340;&#32972;&#26223;&#33394;&#65292;&#27880;&#24847;&#19979;&#38754;&#20004;&#31181;&#26041;&#27861;&#31561;&#25928;</span>
                text.setBackgroundResource(colorIds[position]);
                text.setTextSize(20);
                text.setTextSize(getResources()
                    .getInteger(R.integer.font_size));
                <span style="color: #80A0C2;">return</span> text;
            }
        };
        <span style="color: #ECCC87;">GridView</span> <span style="color: #dac6d6;">grid</span> = (<span style="color: #ECCC87;">GridView</span>)findViewById(R.id.grid01);
        <span style="color: #75715E;">// </span><span style="color: #747474;">&#20026;GridView&#35774;&#32622;Adapter</span>
        grid.setAdapter(ba);
    }
}
</pre>
</div>
</div>
</div>
</div>

<div id="outline-container-sec-2" class="outline-2">
<h2 id="sec-2"><span class="section-number-2">2</span> Android应用国际化实训</h2>
<div class="outline-text-2" id="text-2">
</div><div id="outline-container-sec-2-1" class="outline-3">
<h3 id="sec-2-1"><span class="section-number-3">2.1</span> 项目实现过程:</h3>
<div class="outline-text-3" id="text-2-1">
<ol class="org-ol">
<li>在Android Studio中新建空白项目，并将其命名为InternationalDemo
</li>
<li>在res/目录下完成图片资源在drawable-en-rUS和drawable-zh-rCN中的添加，文本资源strings.xml文件在values-en-rUS和
value-zh-rCN中的添加。
</li>
<li>添加控件，完成layout目录下布局文件。
</li>
<li>对java文件进行功能增加，完成代码。
</li>
</ol>
</div>
</div>
<div id="outline-container-sec-2-2" class="outline-3">
<h3 id="sec-2-2"><span class="section-number-3">2.2</span> 关键代码</h3>
<div class="outline-text-3" id="text-2-2">
<ol class="org-ol">
<li>在res中的values-zh-rCN目录下定义的strings.xml文件:
<div class="org-src-container">

<pre class="src src-xml">&lt;?<span style="color: #80A0C2;">xml</span> <span style="color: #dac6d6;">version</span>=<span style="color: #A2BF8A;">"</span><span style="color: #A2BF8A;">1.0</span><span style="color: #A2BF8A;">"</span> <span style="color: #dac6d6;">encoding</span>=<span style="color: #A2BF8A;">"</span><span style="color: #A2BF8A;">utf-8</span><span style="color: #A2BF8A;">"</span>?&gt;
&lt;<span style="color: #8EBCBB;">resources</span>&gt;
  &lt;<span style="color: #8EBCBB;">string</span> <span style="color: #dac6d6;">name</span>=<span style="color: #A2BF8A;">"</span><span style="color: #A2BF8A;">ok</span><span style="color: #A2BF8A;">"</span>&gt;&#30830;&#23450;&lt;/<span style="color: #8EBCBB;">string</span>&gt;
  &lt;<span style="color: #8EBCBB;">string</span> <span style="color: #dac6d6;">name</span>=<span style="color: #A2BF8A;">"</span><span style="color: #A2BF8A;">cancel</span><span style="color: #A2BF8A;">"</span>&gt;&#21462;&#28040;&lt;/<span style="color: #8EBCBB;">string</span>&gt;
  &lt;<span style="color: #8EBCBB;">string</span> <span style="color: #dac6d6;">name</span>=<span style="color: #A2BF8A;">"</span><span style="color: #A2BF8A;">msg</span><span style="color: #A2BF8A;">"</span>&gt;&#20320;&#22909;&#21834;&#65292;&#21487;&#29233;&#30340;&#23567;&#26426;&#22120;&#20154;&#65281;&lt;/<span style="color: #8EBCBB;">string</span>&gt;
&lt;/<span style="color: #8EBCBB;">resources</span>&gt;
</pre>
</div>
</li>

<li>在res中的value-zh-rUS目录下定义的strings.xml文件:
<div class="org-src-container">

<pre class="src src-xml">&lt;<span style="color: #8EBCBB;">resources</span>&gt;
  &lt;<span style="color: #8EBCBB;">string</span> <span style="color: #dac6d6;">name</span>=<span style="color: #A2BF8A;">"</span><span style="color: #A2BF8A;">ok</span><span style="color: #A2BF8A;">"</span>&gt;OK&lt;/<span style="color: #8EBCBB;">string</span>&gt;
  &lt;<span style="color: #8EBCBB;">string</span> <span style="color: #dac6d6;">name</span>=<span style="color: #A2BF8A;">"</span><span style="color: #A2BF8A;">cancel</span><span style="color: #A2BF8A;">"</span>&gt;Cancel&lt;/<span style="color: #8EBCBB;">string</span>&gt;
  &lt;<span style="color: #8EBCBB;">string</span> <span style="color: #dac6d6;">name</span>=<span style="color: #A2BF8A;">"</span><span style="color: #A2BF8A;">msg</span><span style="color: #A2BF8A;">"</span>&gt;Hello , Android!&lt;/<span style="color: #8EBCBB;">string</span>&gt;
&lt;/<span style="color: #8EBCBB;">resources</span>&gt;
</pre>
</div>
</li>

<li>Java关键代码如下:
<div class="org-src-container">

<pre class="src src-java"><span style="color: #80A0C2;">public</span> <span style="color: #80A0C2;">class</span> <span style="color: #ECCC87;">MainActivity</span> <span style="color: #80A0C2;">extends</span> <span style="color: #ECCC87;">Activity</span>
{
    <span style="color: #ECCC87;">TextView</span> <span style="color: #dac6d6;">tvShow</span>;
    <span style="color: #B58DAE;">@Override</span>
    <span style="color: #80A0C2;">public</span> <span style="color: #ECCC87;">void</span> <span style="color: #8EBCBB;">onCreate</span>(<span style="color: #ECCC87;">Bundle</span> <span style="color: #dac6d6;">savedInstanceState</span>)
    {
        <span style="color: #80A0C2;">super</span>.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tvShow = (<span style="color: #ECCC87;">TextView</span>) findViewById(R.id.show);
        <span style="color: #75715E;">// </span><span style="color: #747474;">&#35774;&#32622;&#25991;&#26412;&#26694;&#25152;&#26174;&#31034;&#30340;&#25991;&#26412;</span>
        tvShow.setText(R.string.msg);
    }
}
</pre>
</div>
</li>
</ol>
</div>
</div>
</div>
</div>
<div id="postamble" class="status">
<p class="author">Author: jacklisp</p>
<p class="date">Created: 2019-09-09 一 23:42</p>
<p class="creator"><a href="http://www.gnu.org/software/emacs/">Emacs</a> 25.2.2 (<a href="http://orgmode.org">Org</a> mode 8.2.10)</p>
<p class="validation"><a href="http://validator.w3.org/check?uri=referer">Validate</a></p>
</div>
</body>
</html>